package deploy

import (
	"fmt"
	APPV1 "k8s.io/api/apps/v1"
	CoreV1 "k8s.io/api/core/v1"
	MetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"kubeUser/internal/pkg/client"
)



// 创建deploy
func CreateDeploy(DeployName,NameSpace string)  {
		var rs int32
		rs = 2
		lable := map[string]string{}
		lable["apps"] = "nginx"
		_,err :=client.KubeManger.ClientSet.AppsV1().Deployments("default").Create(&APPV1.Deployment{
			TypeMeta: MetaV1.TypeMeta{
				Kind: "Deployment",
				APIVersion: "apps/v1",
			},
			ObjectMeta: MetaV1.ObjectMeta{
				Name: DeployName,
				Namespace: NameSpace,
			},
			Spec: APPV1.DeploymentSpec{
				Selector: &MetaV1.LabelSelector{
					MatchLabels: lable,
				},
				Replicas: &rs,
				Template: CoreV1.PodTemplateSpec{
					ObjectMeta: MetaV1.ObjectMeta{
						Labels: lable,
					},
					Spec: CoreV1.PodSpec{

						Containers: []CoreV1.Container{
							{
								Name: DeployName,
								Image: "nginx",
							},
						},
					},
				},
			},
		})

		if err != nil {
			fmt.Println(err)
		}


}